#!/usr/bin/env python
import webbrowser
import urllib


def pydoc(cmdstr, cmdargs):
    #First try getting the page.
    j = urllib.urlopen("http://docs.python.org/library/%s.html" % (cmdargs[0]))
    #if it exists open it up.
    if j.getcode() == 200:
        webbrowser.open("http://docs.python.org/library/%s.html" % (cmdargs[0]))
    else:
        #Try an I'm feeling lucky page.
        webbrowser.open("http://www.google.com/search?btnI=I%%27m+Feeling+Lucky&ie=UTF-8&oe=UTF-8&q=%s%%20site:docs.python.org" % (cmdargs[0]))


TRIGGERS = {
            "pydoc":pydoc,
            "pythondoc":pydoc
            }
#webbrowser.open("http://www.google.com/search?btnI=I%27m+Feeling+Lucky&ie=UTF-8&oe=UTF-8&q=python sys")
